<?php
class Yahoo_Status extends WP_Widget { 
 
    //Kh?i t?o contructor c?a 1 l?p 
    function Yahoo_Status(){ 
        parent::WP_Widget('Yahoo_Status_Widget', 
            '05 - Yahoo Status', 
            array('description' => 'Status nick yahoo.')); 
    }
	function widget( $args, $instance ) { 
        extract($args); 
        $title = apply_filters( 'widget_title', 
            empty($instance['title']) ? '' : $instance['title'], 
            $instance, $this->id_base); 
        $text = apply_filters( 'widget_text', 
            $instance['text'], $instance ); 
			// vinh-09324006-leseawuyhs|ba-0940 409-giacmo
			/*define: 
				name: vinh
				phone: 0932400606
				nick :leeseawuyhs
			
			*/
			$args_yahoo_info = array();
			$args_texts = explode("|", $text);
			//var_dump($args_texts);
			if(!empty($args_texts)){
				$i =0;
				foreach ($args_texts as $args_text){
					$set_args_texts = explode(";",$args_text);
					//var_dump($set_args_texts);
						if(isset($set_args_texts[0]) && (strlen(trim($set_args_texts[0]))))
							$args_yahoo_info[$i]['name'] = trim($set_args_texts[0]);
						if(isset($set_args_texts[1])  && (strlen(trim($set_args_texts[1]))))
							$args_yahoo_info[$i]['phone'] = trim($set_args_texts[1]);
						if(isset($set_args_texts[2])  && (strlen(trim($set_args_texts[2]))))
							$args_yahoo_info[$i]['nick'] = trim($set_args_texts[2]);
					$i++;
				}
			}
		//var_dump($args_yahoo_info);
		if(!empty($args_yahoo_info)){
        echo $before_widget; 
        if ( !empty( $title ) ) { 
            echo $before_title . $title . $after_title; } ?> 
			
            <ul class="nick_status"> 
            <?php 
						foreach($args_yahoo_info as $args_yahoo):
							echo '<li class="li_box">';
								if(isset($args_yahoo['name']))
									echo $args_yahoo['name'];
								if(isset($args_yahoo['phone']))
									echo '('.$args_yahoo['phone'].')&nbsp;';
								if(isset($args_yahoo['nick']))
										echo '&nbsp;|&nbsp;<a href="ymsgr:sendIM?'.$args_yahoo['nick'].'">'.$args_yahoo['nick'].'<img src="http://presence.msg.yahoo.com/online?u='.$args_yahoo['nick'].'&m=g&t=5&l=us"/></a>';
							echo '</li>';
						endforeach; 
            ?> 
            </ul> 
			
        <?php 
        echo $after_widget; 
		}
    }

	function update( $new_instance, $old_instance ) { 
    $instance = $old_instance; 
    $instance['title'] = strip_tags($new_instance['title']); 
    if ( current_user_can('unfiltered_html') ) 
        $instance['text'] =  trim($new_instance['text']); 
    else
        $instance['text'] = trim(stripslashes( 
            wp_filter_post_kses( addslashes($new_instance['text']) ) 
        )); 
    return $instance; 
}
function form( $instance ) { 
        $instance = wp_parse_args( (array) $instance, 
            array( 'title' => '', 'text' => '' ) ); 
        $title = strip_tags($instance['title']); 
        $text = trim(format_to_edit($instance['text'])); 
?> 
        <p> 
            <label for="<?php echo $this->get_field_id('title'); ?>"> 
                <?php _e('Title:'); ?> </label> 
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
                name="<?php echo $this->get_field_name('title'); ?>" type="text"
                value="<?php echo  esc_attr($title);?>" /> 
        </p> 
            <label for="<?php echo $this->get_field_id('text'); ?>"> 
                <?php _e("Nick yahoo(Space by','):"); ?> </label> 
				
            <textarea class="widefat" rows="5" cols="10"
                id="<?php echo $this->get_field_id('text'); ?>"
                name="<?php echo $this->get_field_name('text'); ?>"> 
                    <?php echo trim($text);?> 
            </textarea> 
        <p> 
            <label for="<?php echo $this->get_field_id('text'); ?>"> 
                <?php _e('Desfine:<br/>
					name1;phone1;nick1&nbsp;<b>|</b>&nbsp;name2;phone2;nick2<br/>
					if field "phone" is empty: name1;;nick
				'); ?> 
            </label> 
        </p> 
<?php 
    } 
} 
  
register_widget('Yahoo_Status'); 
